var alagisUtil = function(){

    function numToFixed(num){
        return Math.floor(num * 10000) / 10000;
    }

    // BMap.Point
    function edushiToBaidu(alagisPointArray){
        let point = null;
        let alagisPoint = alagis.proj.transform(alagis.util.mtoEdushi(alagisPointArray), 'EPSG:3857', 'EPSG:4326');
        $.ajax({
            url:'/map/ctbdp.do',
            async:false,
            data:{coords:alagisPoint.join(",")},
            dataType:'json',
            success:function(res){
                if(res.success){
                    point = new BMap.Point(res.obj.x, res.obj.y);
                }
            }

        });
        return point;
    }

    //array
    function baiduToEdushi(point){
        let bd09togcj02=coordtransform.bd09togcj02(point.lng, point.lat);
        let  gcj02towgs84=coordtransform.gcj02towgs84(bd09togcj02[0], bd09togcj02[1]);
        // for(var i=0;i<10;i++){
        //     var std=coordtransform.bd09togcj02(122.22591192587979, 40.66581152344314);
        //     var  tdd=coordtransform.gcj02towgs84(std[0], std[1]);
        //     console.log('converted',tdd.map(x=>numToFixed(x)))
        // }
        let res = gcj02towgs84.map(x=>numToFixed(x));
        return res;
    }

    function gcjToEdushi(point){
        let gcj02towgs84=coordtransform.gcj02towgs84(point.lng, point.lat);
        return  alagis.util.etoMercator(alagis.proj.transform(gcj02towgs84, 'EPSG:4326', 'EPSG:3857'));
    }

    function gcjToBaidDuPoint(point){
        var gcj02tobd09=coordtransform.gcj02tobd09(point.lng, point.lat);
        return new BMap.Point(gcj02tobd09[0], gcj02tobd09[1]);
    }

    function addIconFeature(elementId,pointArray,map) {
        let anchor = new alagis.Overlay({
            id:elementId,
            element: document.getElementById(elementId)
        });
        anchor.setPosition(pointArray);
        map.addOverlay(anchor);
    }

    return {
        edushiToBaidu:function(arr){
            return edushiToBaidu(arr);
        },
        baiduToEdushi:function(point){
            return baiduToEdushi(point);
        },
        gcjToEdushi:function(point){
            return gcjToEdushi(point);
        },
        gcjToBaidDuPoint(point){
            return gcjToBaidDuPoint(point);
        },
        addIconFeature(elementId,point,map){
            let pointArray = gcjToEdushi(point);
            addIconFeature(elementId,pointArray,map);
        }
            
    }
}();